<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use EasyWeChat\Factory;
/**
 * 短信接口
 */
class PaymentController {

    //支付
    public function native(Request $request) {

        $all = $request->all();
        $config = config('wechat.payment');
        $payment = Factory::payment($config);
        $order = [
            'out_trade_no' => time(), // 商户订单号，需保证唯一性
            'body' => '测试商品', // 商品描述
            'total_fee' => 1, // 订单总金额，单位为分
            'spbill_create_ip' => request()->ip(), // 客户端 IP 地址
            'notify_url' => $config['notify_url'], // 支付结果通知地址
            'trade_type' => 'NATIVE', // 交易类型，NATIVE 表示扫码支付
        ];

        $result = $payment->order->unify($order);
        if ($result['return_code'] === 'SUCCESS' && $result['result_code'] === 'SUCCESS') {
            $codeUrl = $result['code_url'];
            return response()->json(['code_url' => $codeUrl]);
        } else {
            return response()->json(['error' => $result['return_msg']], 400);
        }
    }

}
